package com.zf.yichat.controller.verification;

import com.github.pagehelper.PageHelper;
import com.zf.yichat.controller.BaseController;
import com.zf.yichat.im.mapper.RcVerificationCodesMapper;
import com.zf.yichat.model.RcVerificationCodes;
import com.zf.yichat.utils.common.DtoChangeUtils;
import com.zf.yichat.utils.response.FsResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 一句话描述功能
 *
 * @author fengsong
 * @date create in 10:34 2019/9/6 2019
 */
@Controller
@RequestMapping("verification")
public class VerificationController extends BaseController {

    @Resource
    private RcVerificationCodesMapper verificationCodesMapper;

    @RequestMapping("index")
    public String index() {
        return "verification/index";
    }


    @RequestMapping("/list")
    @ResponseBody
    public FsResponse list(Integer page, Integer limit, String phone) {

        Example example = new Example(RcVerificationCodes.class);
        if(Objects.nonNull(phone)){
            example.createCriteria().andLike("phone","%"+phone+"%");
        }
        example.setOrderByClause(" updatedAt desc");
        PageHelper.startPage(page, limit);
        return DtoChangeUtils.getPageList(verificationCodesMapper.selectByExample(example), v -> v);
    }
}
